<?php //return; // Create Product tables and then run this test 
require_once('lanceur_spip.php');
require_once(_DIR_PLUGIN_PDK.'classes/simpletest/class.PdkModelTest.php');
include_spip('functions/pdk_common');
class TestClassProductModel extends PdkModelTest {
    /**
     *  Pdk Category
     */
    private $category_mdl;
    
    public function __construct(){
        parent::__construct();
        
        // Define models that will be used for this test
        $pdk_models = array();
        $this->category_mdl = pdk_load_class('PdkCategoryModel','classes');
        $pdk_models['PdkCategoryModel'] = $this->category_mdl;
        
        $this->AddPdkModels($pdk_models);
        
        // Define main tested model
        $this->SetPdkModel('PdkProductModel', pdk_load_class('PdkProductModel', 'classes'));
        
        $this->dropTestTables = false;
    }
    
    /**
     *  Run before each test
     */
    function setUp() {
        parent::setUp();
    }
    
    /**
     *  Run after each test
     */
    function tearDown() {
        parent::tearDown();
    }
    
    function __destruct() {
        // Call parent destructor to delete created tables
        parent::__destruct();
    }
	
	function TestSelectReferenceToArray() {		
		$products_check = array(1=>'Test product 1',2=>'Test product 2',3=>'Test product 3',4=>'Test product 4');
		$products = $this->model->SelectReferenceToArray('titre');		
		$this->assertEqual($products_check, $products);		
		
		$products_check = array(3=>'Test product 3', 4=>'Test product 4');
		$products = $this->model->SelectReferenceToArray('titre', null, 'prix>700');
		$this->assertEqual($products_check, $products);
		
		$this->model->update_by_id(1, array('title'=>'01. Test product 1'));
		$this->model->update_by_id(2, array('title'=>'02. Test product 2'));		
		$products_check = array(1=>'Test product 1', 2=>'Test product 2');
		$products = $this->model->SelectReferenceToArray('titre', null, 'prix<700', false, false, true);
		$this->assertEqual($products_check, $products);
		$products_check = array(1=>'01. Test product 1', 2=>'02. Test product 2');
		$products = $this->model->SelectReferenceToArray('titre', null, 'prix<700');
		$this->assertEqual($products_check, $products);
	}
}
